package Class_03_15;

import java.util.Scanner;

public class BinarySearch {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[10];
        System.out.println("请依次从小到大输入十个数");
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }

        System.out.println("请输入要查找的数据");
        int flag = sc.nextInt();
        Sort(arr,flag);


    }
    public static void Sort(int[] arr,int flag)
    {
        int left = 0;
        int right = arr.length - 1;
        while(left <= right)
        {
            int mid = (left + right) / 2;
            if(arr[mid] > flag)
            {
                right = mid;
            } else if (arr[mid] < flag) {
                left = mid;
            }else {
                System.out.println("找到了,该数据下标为" + mid);
                break;
            }
        }
        System.out.println("未找到该数据");
    }
}
